package models.dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import models.LoginUsuario;

public class DAOLoginUsuario
{
	public boolean login(LoginUsuario l){
		
		try{
//			String query = "select * from Usuario where email = "+ l.email +" and senha = "+ l.senha;
			String query = String.format("select * from Usuario where email = \'%s\' and senha = \'%s\' ", l.email, l.senha);
			PreparedStatement statement = DAOConexao.getConnection().prepareStatement(query);
			ResultSet resultset = statement.executeQuery();
			
			if(resultset.next())
				return true;
			return false;
			
			
		}catch(SQLException e){
			System.out.println(e.getMessage());
		}
		
		return false;
	}
	
	public LoginUsuario perfil(LoginUsuario l){
		LoginUsuario lu = new LoginUsuario();
		
		try{
			String query = String.format("select * from Usuario where email = \'%s\' and senha = \'%s\' ", l.email, l.senha);
			PreparedStatement statement = DAOConexao.getConnection().prepareStatement(query);
			ResultSet resultset = statement.executeQuery();
			
			lu.email = resultset.getString(1);
			lu.senha = resultset.getString(2);
			lu.perfil = resultset.getString(3);
			
			
		}catch(SQLException e){
			System.out.println(e.getMessage());
		}
		
		return lu;
	}
}
